/**
 * 
 */

function restrictToAlphabet(event)
{
	if((event.keyCode >= 48 && event.keyCode <= 57) || (event.keyCode >= 96 && event.keyCode <= 105))
		event.preventDefault();
	
}

function restrictToNumbers(event)
{
	 if ( event.keyCode == 46 || event.keyCode == 8 || event.keyCode == 9 || event.keyCode == 27 || event.keyCode == 13 || 
         // Allow: Ctrl+A
        (event.keyCode == 65 && event.ctrlKey === true) || 
         // Allow: home, end, left, right
        (event.keyCode >= 35 && event.keyCode <= 39)) {
             // let it happen, don't do anything
             return;
    }
    else {
        if (event.shiftKey || (event.keyCode < 48 || event.keyCode > 57) && (event.keyCode < 96 || event.keyCode > 105 )) {
            event.preventDefault(); 
        }   
    }
}

function restrictToNumberCurr(event)
{
	 if ( event.keyCode == 46 || event.keyCode == 8 || event.keyCode == 9 || event.keyCode == 27 || event.keyCode == 13 || 
         // Allow: Ctrl+A
        (event.keyCode == 65 && event.ctrlKey === true) || 
         // Allow: home, end, left, right
        (event.keyCode >= 35 && event.keyCode <= 39) || 
        // Allow:  . and ,
        (event.keyCode == 110 || event.keyCode == 190 || event.keyCode == 188))
	 	{
             // let it happen, don't do anything
             return;
    }
    else {
        if (event.shiftKey || (event.keyCode < 48 || event.keyCode > 57) && (event.keyCode < 96 || event.keyCode > 105 )) {
            event.preventDefault(); 
        }   
    }
}

function validateDateMMDDYYYY(event, divErrMsg)
{
	var dateRegexp = /^[01]?[0-9]\/[0-3]?[0-9]\/[12][0-9][0-9][0-9]$/;
	var errMsg = "";
	if(event.target.value != "")
	{
		if(!event.target.value.match(dateRegexp))
			errMsg = "Invalid date.";
		else
		{
			var dateArr = event.target.value.split("/");
			var monthVal = parseInt(dateArr[0], 10);
			var dayVal = parseInt(dateArr[1], 10);
			
			if(monthVal > 12)
				errMsg = "Invalid date.";
			else if(dayVal > 31)
				errMsg = "Invalid date.";
		}
	}
	
	divErrMsg.empty().append( errMsg );
}

function validateEmailAddress(event, divErrMsg) 
{
	var errMsg = "";
    var emailRegexp = /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i;
    if(event.target.value != "")
    {
	    if(!event.target.value.match(emailRegexp))
	    	errMsg =  "Invalid email.";
    }
   	
   	divErrMsg.empty().append(errMsg);
}

function restrictAlphabetOnPaste(event)
{
	alert(event.target.val());
	var regexp = /[a-zA-Z]/;
		checktest = event.target.value.match(regexp);
	if(checktest!= null){
		alert('Only alphabet is allowed.');
		obj.value = "";
	}	
}

function restrictNumericOnPaste(event)
{
	var regexp = /[^0-9.]/;
	checktest = event.target.value.match(regexp);
	if(checktest!= null){
		alert('Only number is allowed!');
		obj.value = "";
	}
}

